# Maintainer: Sergej Pupykin <arch+pub@sergej.pp.ru>

pkgname=darkhttpd
pkgver=1.14
pkgrel=1
pkgdesc="A small and secure static webserver"
arch=('loong64' 'x86_64')
url="https://unix4lyfe.org/darkhttpd/"
license=('BSD')
backup=('etc/conf.d/mimetypes')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/emikulic/darkhttpd/archive/v${pkgver}.tar.gz"
        'darkhttpd.service'
        'darkhttpd@.service')
sha256sums=('e063de9efa5635260c8def00a4d41ec6145226a492d53fa1dac436967670d195'
            'e53ae82993f6c996c0c54ccbbd9307811501cf01404c441b48b2c79f9384fa27'
            '0bfbe13c93ba87d8ea08ab85745c92cebcbc6b627616e7c58d6099a234a59841')

build() {
  cd "$srcdir/$pkgname-$pkgver"

  make
}

package() {
  cd "$srcdir/$pkgname-$pkgver"

  # install darkhttpd
  install -Dm755 "$srcdir/$pkgname-$pkgver/darkhttpd" "$pkgdir/usr/bin/darkhttpd"

  # install systemd files
  install -Dm644 "$srcdir/darkhttpd.service" "$pkgdir/usr/lib/systemd/system/darkhttpd.service"
  install -Dm644 "$srcdir/darkhttpd@.service" "$pkgdir/usr/lib/systemd/system/darkhttpd@.service"
  install -dm0755 "$pkgdir"/etc/conf.d/
  touch "$pkgdir"/etc/conf.d/mimetypes

  # install license
  install -d "$pkgdir/usr/share/licenses/$pkgname"
  sed -n '1,/^$/p' darkhttpd.c > "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
